programming4us
           
 
 
Programming

Coding JavaScript for Mobile Browsers (part 4)

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/25/2010 3:26:38 PM
2.4. Platform detection

JavaScript has a native navigator object representing the client browser on which the code is running. We can use this technique to detect what device our code is running on and make a decision based upon that.


Note:

When using a for, remember to define the index variable as a local file with var i=initial_value. If not, you’ll be using a global variable, which can have some performance and bug issues.


The navigator object has many properties, but the most useful are appName (the browser’s name), appVersion (the browser’s version), mimeTypes (an array of supported MIME types), plugin (an array of supported plug-ins for object tag), platform (the operating system), and userLanguage.

Generally, we will use the string’s indexOf function to verify whether some of these attributes have the values we are looking for. For example:

// Detects if it is an Android device
var android = (navigator.platform.indexOf("android")>=0);
if (android) {
// Do something
}

Table 6 shows what is returned from these properties for each browser. In this table, assume that <User Agent> will be replaced with each device’s user agent ID.

Table 6. JavaScript navigator object properties compatibility table
Browser/ PlatformappNameappVersionmimeTypesplatform
SafariNetscape5.0 (<User Agent>)ArrayiPhone, iPod, or iPad
Android browserNetscape5.0 (<User Agent>)Arraynull
Symbian/S60Netscape5.0 (<User Agent>)ArrayS60
Nokia Series 40 before 6th editionNokiaEmpty stringUndefinedUndefined
Nokia Series 40 6th editionNetscape2.0UndefinedNokia_Series_40
webOSNetscape5.0 (<User Agent>)ArraywebOS
BlackBerryNetscape<Platform version>ArrayBlackBerry
NetFrontACCESS NetFront<Browser version>ArrayUnknown
Internet ExplorerMicrosoft IE MobileEmpty stringUndefinedWinCE
Motorola Internet BrowserNetscape5.0ArrayWiderWeb
Opera MobileOpera<opera engine version> (Symbian or Windows)ArraySymbian or Windows
Opera MiniOpera<opera engine version>ArrayPike

2.5. Window size

JavaScript has two objects related to sizes: document.documentElement and screen. The first is related to the size of the current document’s viewport, and the second to the whole screen of the device. At the time of writing, there is no browser that allows windows smaller than the whole screen. We can create web widgets for the home screen on many devices.


Note:

BlackBerry devices have a global variable, blackberry, that has two objects: location and network. The network property allows us to know whether the user is using WiFi, GPRS, EDGE, CDMA, or some other network. Android Browser, from 2.2, also has a similar property: navigator.connection.type.


The screen object has four properties: width, height, availWidth, and availHeight. The last two refer to the size available taking into account the space used by the operating system toolbars. In the mobile space, they are generally the same as the width and height values.

The most commonly used way to get the window size is via document.documentElement.clientWidth and document.documentElement.clientHeight.

The only way for these values to change while the page is loaded is in response to an orientation change, on compatible devices (landscape to portrait and vice versa). Table 7 shows which browsers can access information about the screen and window size and which support orientation changes.

Table 7. Screen properties and events compatibility table
Browser/platformScreen sizeWindow sizeOrientation change
SafariYesYesonorientationchange and onresize
Android browserYesYesonresize
Symbian/S60Yes, different in full-screen modeYesonresize
Nokia Series 40No before 6th editionNo before 6th editionNo
webOSYesViewport sizeonresize
BlackBerryNo before 4.6Nodocument.onresize in some devices
NetFrontYesNoNo
Internet ExplorerYesNoNo
Motorola Internet BrowserYesYesNo
Opera MobileYesYesNo
Opera MiniYesYesNo
Other -----------------
- Programming the Mobile Web : JavaScript Mobile - Supported Technologies
- Security in Cloud Computing (part 4) - Audit and Compliance
- Security in Cloud Computing (part 3)
- Security in Cloud Computing (part 2) - Identity and Access Management
- Security in Cloud Computing (part 1) - Data Security and Storage
- Cloud Security and Privacy : Analyst Predictions
- CSS for Mobile Browsers : WebKit Extensions (part 2) - Border Image
- CSS for Mobile Browsers : WebKit Extensions (part 1) - Text Stroke and Fill
- jQuery 1.3 : Working with numeric form data (part 9) - The finished code
- jQuery 1.3 : Working with numeric form data (part 8) - Editing shipping information
- jQuery 1.3 : Working with numeric form data (part 7) - Deleting items
- jQuery 1.3 : Working with numeric form data (part 6) - Finishing touches
- jQuery 1.3 : Working with numeric form data (part 5)
- jQuery 1.3 : Working with numeric form data (part 4) - Dealing with decimal places
- jQuery 1.3 : Working with numeric form data (part 3) - Parsing and formatting currency
- jQuery 1.3 : Working with numeric form data (part 2)
- jQuery 1.3 : Working with numeric form data (part 1) - Shopping cart table structure
- The Art of SEO : Controlling Content with Cookies and Session IDs
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 5) - The Freehand Tool
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 4) - The Ellipse and Rectangle Tools
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us